package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

public class BaseServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String url=request.getRequestURI();
        int g=url.lastIndexOf("/");
        String name=url.substring(g+1);
        System.out.println("run "+name);
        try {
            Method m=this.getClass().getDeclaredMethod(name,HttpServletRequest.class,HttpServletResponse.class);
            m.invoke(this,request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
